//
//  AlbumCollectionViewCell.m
//  WOFishingBoat
//
//  Created by 郑逸凯 on 2018/12/27.
//  Copyright © 2018年 郑逸凯. All rights reserved.
//

#import "AlbumCollectionViewCell.h"
#import <Masonry/Masonry.h>
#import "UIImageView+WoWebCache.h"

@interface AlbumCollectionViewCell ()
@property (nonatomic,strong)UIImageView *imageView;
@property (nonatomic,strong)UILabel *titleLabel;
@property (nonatomic,strong)UILabel *numberLabel;
@end

@implementation AlbumCollectionViewCell

#pragma mark - Life Cycle
- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
        [self setupSubviews];
        [self performLayout];
    }
    return self;
}
#pragma mark - Public Methods
- (void)reloadCell:(id)model {
    if (model && [model isKindOfClass:AlbumModel.class]) {
        AlbumModel *albumModel = model;
        self.titleLabel.text = albumModel.shipName;
        self.numberLabel.text = [NSString stringWithFormat:@"%li",albumModel.imgCount];
        [self.imageView  wo_setImageWithURL:albumModel.latestImg];
    }
}

#pragma mark - Responder Actions
#pragma mark - Delegates
#pragma mark - Private Methods
- (void)setupSubviews {
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.imageView];
    [self.contentView addSubview:self.numberLabel];
}

- (void)performLayout {
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.contentView);
        make.width.height.mas_equalTo(self.contentView.frame.size.width);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imageView.mas_bottom);
        make.left.width.equalTo(self.contentView);
        make.height.mas_equalTo(20);
    }];
    
    [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom);
        make.left.width.equalTo(self.contentView);
        make.height.mas_equalTo(20);
    }];
}
#pragma mark - Setters and Getters
#pragma mark - Helper

- (UIImageView *)imageView {
    if (!_imageView ) {
        _imageView = [[UIImageView alloc] init];
        _imageView.layer.masksToBounds = YES;
        _imageView.layer.cornerRadius = 10;
        
    }
    return _imageView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.textColor = RGB16(0x333333);
        label.font = [UIFont systemFontOfSize:14];
        _titleLabel = label;
    }
    return _titleLabel;
}

- (UILabel *)numberLabel {
    if (!_numberLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.textColor = RGB16(0x999999);
        label.font = [UIFont systemFontOfSize:12];
        _numberLabel = label;
    }
    return _numberLabel;
}



@end
